package com.mxpio.erp.common.purchase.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.technology.entity.ItemGroup;
import com.mxpioframework.jpa.annotation.DictAble;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "V_MB_ERP_PURC_PO_LINE_EXEC_DETAIL")
@Schema(description="采购订单明细执行详情视图")
public class VPurchaseOrderLineExecDetail implements DictAble, Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "ID", updatable = false)
	@Schema(description = "主键")
	private String id;

	@Column(name = "ORDER_DATE_")
	@Schema(description = "单据日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date orderDate;

	@Column(name = "BIZ_NO_")
	@Schema(description = "采购单号")
	private String bizNo;

	@Column(name = "ORDER_STATUS_")
	@Schema(description = "单据执行状态")
	@Dict(dicCode = "ERP_COMMON_ORDER_STATUS")
	private String orderStatus;

	@Column(name = "LINE_NO_")
	@Schema(description = "行号")
	private String lineNo;

	@Schema(description = "供应商编号")
	@Column(name = "PN_CODE_")
	private String pnCode;

	@Schema(description = "供应商名称")
	@Column(name = "PN_NAME_")
	private String pnName;

	@Column(name = "BIZ_MAN_")
	@Schema(description = "业务员")
	@Dict(dicCode = "username",dicEntity = User.class,dicText = "nickname")
	private String bizMan;

	@Column(name = "ITEM_CODE_")
	@Schema(description = "物料代码")
	private String itemCode;

	@Column(name = "ITEM_GROUP_CODE_")
	@Schema(description = "物料组")
	@Dict(dicCode = "groupCode", dicEntity = ItemGroup.class, dicText = "groupName")
	private String itemGroupCode;

	@Column(name = "ITEM_NAME_")
	@Schema(description = "物料名称")
	private String itemName ;

	@Column(name = "UNIT_CODE_")
	@Schema(description = "单位编号")
	@Dict(dicCode="ERP_TECH_UNIT_CODE")
	private String unitCode;

	@Column(name = "DRAWING_NO_")
	@Schema(description = "图号")
	private String drawingNo;

	@Column(name = "IN_QUALITY_CONTROL_")
	@Schema(description = "是否检验")
	@Dict(dicCode = "ERP_COMMON_YESNO")
	private String inQualityControl;

	@Column(name = "ORDER_QUANTITY_")
	@Schema(description = "采购数量")
	private BigDecimal orderQuantity;

	@Column(name = "RECEIVE_QUANTITY_")
	@Schema(description = "(到货)交检数量")
	private BigDecimal receiveQuantity;


	@Column(name = "QUALIFIED_QUANTITY_")
	@Schema(description = "验收合格数量")
	private BigDecimal qualifiedQuantity;

	@Column(name = "STOCK_QUANTITY_")
	@Schema(description = "实际交货数量")
	private BigDecimal stockQuantity;

	@Schema(description = "(建议)到货日期")
	@Column(name = "SUGGEST_ARRIVE_DATE_")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date suggestArriveDate;

	@Schema(description = "验收日期(物料质检单最后一次验收完成时间)")
	@Column(name = "last_inspection_finish_time_")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date lastInspectionFinishTime;


	@Schema(description = "实际到货日期(物料流水最后一次入库时间)")
	@Column(name = "last_stock_time_")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date lastStockTime;

	@Transient
	private Map<String, String> textMap;

	public String putText(String key, String value) {
		if (textMap == null) {
			textMap = new HashMap<>();
		}
		return textMap.put(key, value);
	}
}
